package com.fight.strive.sys.modules.scheduler.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fight.strive.sys.modules.common.PageR;
import com.fight.strive.sys.modules.common.ReStatus;
import com.fight.strive.sys.modules.scheduler.entity.SchRecordEntity;
import com.fight.strive.sys.modules.scheduler.service.SchRecordService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/admin/sys/scheduler/record")
public class SchRecordController {

    @Resource
    private SchRecordService schRecordService;

    @PostMapping("/list")
    public ReStatus<IPage<SchRecordEntity>> list(
            @RequestBody PageR<SchRecordEntity> page) {
        return ReStatus.success(
                schRecordService.list(page));
    }

    @RequestMapping("/get/{id}")
    public ReStatus<SchRecordEntity> getRecord(@PathVariable String id) {
        return ReStatus.success(
                schRecordService.getById(id));
    }

    @PostMapping("/clear/{ago}")
    public ReStatus<Void> remove(@PathVariable String ago) {
        schRecordService.clearRecord(ago);
        return ReStatus.success();
    }

    @PostMapping("/stackTrace/{id}")
    public ReStatus<SchRecordEntity> get(@PathVariable String id) {
        return ReStatus.success(
                schRecordService.getById(id));
    }
}
